package org.hot100_3;

import java.util.HashSet;

public class leetcode3 {
    public int lengthOfLongestSubstring(String s) {

        int maxLength = 0;
        int n = s.length();

        int left, right;

        HashSet<Character> set = new HashSet<>();

        for (left = 0; left < n; left++) {
            right = left;
            while (right < n && !set.contains(s.charAt(right))) {
                set.add(s.charAt(right));
                right++;
            }
            maxLength = Math.max(maxLength, right - left);
            set.clear();
        }

        return maxLength;
    }
}
